﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace LocalizationLibrary.Tests.Core.Reflection
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.Serialization;
    using System.Text;

    //LocalizationLibrary References
    using DeployPackA.Tests.LocalizationModels;
    using LocalizationLibrary.Attributes;
    using LocalizationLibrary.Reflection;

    //Microsoft References
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class ReflectionCacheTest
    {
        [TestMethod]
        public void Get_Assembly()
        {
            ReflectionCache reflectionCache = ReflectionCache.Create();
            Assembly assembly = Assembly.GetCallingAssembly();
            AssemblyRef assemblyRef = reflectionCache.GetAssemblyRef(assembly);
            AssemblyRef assemblyRef2 = reflectionCache.GetAssemblyRef(assembly);
            Assert.AreEqual(ReferenceEquals(assemblyRef, assemblyRef2), true);
        }

        [TestMethod]
        public void Get_All_Assembly()
        {
            ReflectionCache reflectionCache = ReflectionCache.Create();
            
            Assert.AreEqual(reflectionCache.GetAllAssemblyRef().Length, 0);

            Assembly assembly = Assembly.GetCallingAssembly();
            AssemblyRef assemblyRef = reflectionCache.GetAssemblyRef(assembly);
            AssemblyRef assemblyRef2 = reflectionCache.GetAssemblyRef(assembly);

            Assert.AreEqual(assemblyRef, assemblyRef2);
        }

        [TestMethod]
        public void Get_Type()
        {
            ReflectionCache reflectionCache = ReflectionCache.Create();
            Type type = typeof(String);
            TypeRef typeRef = reflectionCache.GetTypeRef(type);
            TypeRef typeRef2 = reflectionCache.GetTypeRef(type);
            Assert.AreEqual(ReferenceEquals(typeRef, typeRef2), true);
        }
    }
}
